package Cluster;

import java.util.ArrayList;

public class Linkage {
	
	public static final int LINK_SINGLE = 0;
	
	public static double LDist(ClusterBulk cb1, ClusterBulk cb2, int linkType,
			int matricType) {
		double result = 0.0;
		switch(linkType) {
		case Linkage.LINK_SINGLE :
			result =  Linkage.SingleLinkage(cb1, cb2, matricType);
			break;
		}
		return result;
	}
	
	public static double SingleLinkage(ClusterBulk cb1, ClusterBulk cb2, int matricType) {
		ArrayList<Trajectory> listCB1 = cb1.GET002_listTraj();
		ArrayList<Trajectory> listCB2 = cb2.GET002_listTraj();
		double result = 99999.9;
		
		int indexC1 = 0, indexC2 = 0;
		double temp = 0.0;
		while(indexC1 < listCB1.size()){
			indexC2 = 0;
			while(indexC2 < listCB2.size()){
				temp = Matric.MDist(matricType, listCB1.get(indexC1), listCB2.get(indexC2));
				if(temp < result) {
					result = temp;
				}
				indexC2 = indexC2 + 1;
			}
			indexC1 = indexC1 + 1;
		}
		
		return result;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
